
'''
283. 移动零
'''
from typing import List


class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        # 先删除0
        slow = self.removeElement(nums, 0)

        # 将slow后面的补0
        for i in range(slow, len(nums)):
            nums[i] = 0

    def removeElement(self, nums: List[int], val: int) -> int:
        if not nums:
            return 0
        fast = 0
        slow = 0
        while fast < len(nums):
            if nums[fast] != val:
                nums[slow] = nums[fast]
                slow += 1
            fast += 1
        return slow